package controller

import (
	"github.com/gofiber/fiber/v2"
	"guns-excel/internal/app/model"
	"guns-excel/internal/app/service"
	"guns-excel/internal/pkg/util/result"
)

// 新增
func AddModelExcel(ctx *fiber.Ctx) error {
	modelExcel := new(model.ModelExcel)
	if err := ctx.BodyParser(modelExcel); err != nil {
		return ctx.JSON(result.Err.WithMsg("解析参数出错，请检查传参"))
	}
	if err := service.AddModelExcel(ctx, modelExcel); err != nil {
		return ctx.JSON(result.Err.WithMsg("新增失败"))
	}
	return ctx.JSON(result.OK)
}

// 根据模型获取字段
func GetModelExcelByModelId(ctx *fiber.Ctx) error {
	modelId := ctx.Query("modelId")
	modelExcelList, err := service.GetModelExcelByModelId(ctx, modelId)
	if err != nil {
		return err
	}
	return ctx.JSON(result.OK.WithData(modelExcelList))
}
